import { createRouter, createWebHashHistory } from "vue-router";
import Layout from "@/components/Layout/index.vue";

const powerType = import.meta.env.VITE_POWER_TYPE; // 权限类型
/**
 * hidden: true                   如果为true，侧边栏显示，否则是为通用隐藏路由
 * alwaysShow: true               如果为true，将总显示
 *                                如果设置了,路由数量必须大于1
 * redirect: noRedirect           如果设置noRedirect，面包屑不重定向标题
 * meta : {
    role: 'admin'                 路由权限唯一标识
    title: 'title'                路由标题，面包屑展示标题
    icon: 'svg-name'              路由图标
    breadcrumb: false             如果为false，面包屑标题隐藏
  }
 */

// 静态路由

const constantRouters = [
  {
    path: "/",
    name: "index",
    redirect: "/dashboard/index",
  },
  {
    path: "/dashboard",
    name: "Dashboard",
    component: Layout,
    redirect: "/dashboard/index",
    children: [
      {
        name: "Index",
        path: "index",
        component: () => import("@/views/dashboard/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/index.vue"),
  }, {
    path: '/refresh',
    name: 'refresh',
    component: () => import('@/views/populationChange/refresh.vue')
  },

];

// 动态路由
export const asyncRoutes = [
  {
    path: "/household",
    component: Layout,
    name: "household",
    redirect: "/household/create",
    meta: {
      title: "家庭户口立户",
      role: "household",
      icon: "nest",
    },
    children: [
      {
        path: "create",
        name: "household-create",
        component: () => import("@/views/household/create/index.vue"),
        meta: {
          title: "立户",
          icon: "portal-create",
          role: "household-create",
        },
      },
      {
        path: "search",
        name: "household-search",
        component: () => import("@/views/household/search/index.vue"),
        meta: {
          title: "人口信息",
          icon: "eye-open",
          role: "household-search",
        },
      },
    ]
  },
  {
    path: "/residentPopulationManagement",
    component: Layout,
    name: "residentPopulationManagement",
    meta: {
      title: "常驻人口管理",
      icon: "user-filled",
      role:"residentPopulationManagement"
    },
    children: [
      {
        path: "changeIn",
        name: "changeIn",
        component: () => import("@/views/populationChange/index.vue"),
        meta: {
          title: "户口迁入管理",
          icon: "portal",
          role:"changeIn"
        }, children: [
          {
            path: "birth",
            name: "birth",
            component: () => import("@/views/populationChange/birth/index.vue"),
            meta: {
              title: "出生申报",
              icon: "template-audit",
              role:"birth"
            },
          }, {
            path: "couple",
            name: "couple",
            component: () => import("@/views/populationChange/couple/index.vue"),
            meta: {
              title: "夫妻投靠",
              icon: "template-audit",
              role:"couple"
            },
          }, {
            path: "children",
            name: "children",
            component: () => import("@/views/populationChange/children/index.vue"),
            meta: {
              title: "子女投靠",
              icon: "template-audit",
              role:"children"
            },
          },{
            path: "changeRecords",
            name: "changeRecords",
            component: () => import("@/views/populationChange/changeRecords/index.vue"),
            meta: {
            title: "查询记录",
            icon: "template-audit",
            role:"changeRecords"
            },
          },
        ],
      },
      {
        path: "populationChange",
        name: "PopulationChange",
        component: Layout,
        component: () => import("@/views/populationChange/index.vue"),
        meta: {
          title: "户口迁出管理",
          icon: "template",
          role:"populationChange"
        },
        children: [
          {
            path: "death",
            name: "Death",
            component: () => import("@/views/populationChange/death/index.vue"),
            meta: {
              title: "死亡注销",
              icon: "portal-create",
              role: "death"
            },
          },
          {
            path: "emigration",
            name: "Emigration",
            component: () => import("@/views/populationChange/emigration/index.vue"),
            meta: {
              title: "人口迁出",
              icon: "eye-open",
              role: "emigration"
            },
          },
        ]
      },
    ],
  },
  {
    path: "/police",
    component: Layout,
    name: "Policer",

        meta: {
          title: "警员管理",
          role: "police",
          icon: "nest",
        }
        ,
        children: [
          {
            path: "policeofficer",
            name: "policeofficer",
            component: () => import("@/views/police/policeofficer.vue"),
            meta: {
              title: "警员信息",
              icon: "police",
              role: "policeofficer",
            }
          }
          ,
          {
            path:"policeaccount"  ,
            name: "policeaccount",
            component: () => import("@/views/police/policeaccount.vue"),
            meta: {
              title: "警员账号",
              icon: "policeaccount",
              role: "policeaccount",
            }
          }
          ,
          {
            path:"policestation"  ,
            name: "policestation",
            component: () => import("@/views/police/chart.vue"),
            meta: {
              title: "业务可视",
              icon: "eye",
              role: "policeaccount",
            }
          }
        ]
  },
  {
    path: "/migrant",
    component: Layout,
    name: "Migrant",
    redirect: "/migrant",
    meta: {
      role: "migrant",
      icon: "user-filled",
    },
    children: [
      {
        path: "manage",
        name: "migrant-manage",
        component: () => import("@/views/migrant/manage/MigrantManage.vue"),
        meta: {
          title: "流动人口管理",
          icon: "user-filled",
          role: "migrant-manage",
        },
      },
    ],
  },
  {
    path: "/key",
    component: Layout,
    name: "Key",
    redirect: "/key",
    meta: {
      role: "key",
      icon: "user-filled",
    },
    children: [
      {
        path: "manage",
        name: "key-manage",
        component: () => import("@/views/key/manage/KeyManage.vue"),
        meta: {
          title: "重点人口管理",
          icon: "user-filled",
          role: "key-manage",
        },
      },
    ],
  },
  {
    path: "/certificate",
    component: Layout,
    name: "Certificate",
    redirect: "/certificate",
    meta: {
      title: "证件管理",
      role: "certificate",
      icon: "user-paint",
    },
    children: [
      {
        path: "id-manage",
        name: "id-manage",
        component: () => import("@/views/certificate/id/manage/IdCardManage.vue"),
        meta: {
          title: "身份证件管理",
          icon: "user-paint",
          role: "id-manage",
        },
      },
      {
        path: "residence-manage",
        name: "residence-manage",
        component: () => import("@/views/certificate/residence/manage/ResidenceManage.vue"),
        meta: {
          title: "居住证管理",
          icon: "user-paint",
          role: "residence-manage",
        },
      },
    ],
  },
  {
    path: "/extra",
    name: "Extra",
    component: () => import("@/views/404/index.vue"),
    children: [
      {
        path: "https://gitee.com/Wu-Shuqing9557/pdbms_server",
        meta: {
          title: "Git仓库",
          icon: "link",
        },
      },
    ],
  },
  // 重定向放最后
  {
    path: "/:pathMatch(.*)*",
    hidden: true,
    name: "404",
    component: () => import("@/views/404/index.vue"),
  },
];

const allRouter =
  powerType == "1"
    ? constantRouters.concat(asyncRoutes)
    : constantRouters;

export const router = createRouter({
  history: createWebHashHistory(),
  routes: allRouter,
});
